<?php

/*
 * Augabe der Aktoren Seiten
 */

function print_pages_szenen() {
	// Holen der globalen Variablen
	global $version, $theme_data_content, $theme_popup, $theme_data, $theme_overlay, $config_xml, $iconPath;

	$categories_tab = array();
	$actor_tab = array();
	// Aufruf von array_multisort() mit dem Array, das sortiert werden soll und den entsprechenden Flags
	//9 array_multisort($array['id'], $array['rasse'], $array['tier_id']);
	//Einlesen aller Aktoren in array  |Page|SortID|Actor|

	//	Kategorien einlesen und sortieren
	$path = "/config/Categories/Category";
	if (!$res = $config_xml -> xpath($path)) {
		echo "keine Kategorien vorhanden!";
	} else {

		foreach ($res as $category) {
			//	var_dump($actor);
			$CateoryID = $category['sortID'];
			$path = $version;
			//	$SortID = $Page_XML['sortID'];
			$categories_tab[] = $CateoryID;
		}

	}
	// Sortieren der Kategorien

	# sort by event_type desc and then title asc
	asort($categories_tab);
	$pageNum = 0;
	// Body der Seite Anlegen
	print_page_start('Scene', $pageNum);
	print_menu_popup($pageNum);
	print_header_light('Szenen');
	print_page_header($theme_data);
	echo "
				<div data-role=collapsible-set $theme_data data-content-theme='d'>";
	// Nur wenn Aktoren vorhanden, dann auch weitermachen
	foreach ($categories_tab as $CategoryID) {

		$path = '/config/Categories/Category[@sortID=\'' . $CategoryID . '\']';
		$category_xml = $config_xml -> xpath($path);
		//	var_dump($category_xml[0]);
		$title_scene = $category_xml[0]["Name"];
		echo "		
					<div data-role=collapsible>
						<h2>$title_scene</h2>
						<ul data-role=listview data-split-icon=gear data-split-theme=d>";
		//	var_dump($category_xml[0]);
		foreach ($category_xml[0]->Choice as $choice) {

			// Holen der ID der Choice
			$id_scene = $choice["ID"];
			//als Verweis auf die eigentliche Szene
			$path = '/config/Scenes/Scene[@sortID=\'' . $id_scene . '\']';
			$xml_scene = $config_xml -> xpath($path);
			$header_scene = $xml_scene[0]["Name"];
			$header_description = $xml_scene[0]["Beschreibung"];
			$imgPath = $xml_scene[0]->IMG;
			if ($imgPath == '') {
					
				$imgPath = 'default.png';
			};
			
			$imgPath = $iconPath . $imgPath;
			
			echo "
							<li>
								<a href=# onClick=\"perform_light_scene('$id_scene');\"> <img src=$imgPath /> <h3>$header_scene</h3>
								<p>
									$header_description
								</p> </a>
								<a href=# onClick=\"stepPopup('$id_scene', $pageNum)\" data-rel=#popup data-position-to=window data-transition=slideup>Details</a>
							</li>
		
				";
		}
		echo "
						</ul>
					</div>";
	}
	echo "	
			</div>
		</div>";

	print_footer_light("scenes", $pageNum, TRUE);
	print_scene_detail_popup($pageNum);

	print_page_end();




}

function print_scene_detail_popup($pageNum)
	{					
					
	echo "	
			<div data-role=popup id=stepPopup$pageNum data-overlay-theme=a data-theme=c style=max-width:400px; class=ui-corner-all>
				<a href=# data-rel=back data-role=button data-theme=a data-icon=delete data-iconpos=notext class=ui-btn-right>Close</a>
				<div data-role=header id=headerSzene data-theme=a class=ui-corner-top>
					<h1>Szenen Detail</h1>
				</div>
				<div data-role=content data-theme=d class=ui-corner-bottom ui-content id=stepPopupList$pageNum>
					<ul data-role=listview id=stepPopupUL$pageNum>

					</ul>
				</div>
			</div>";					
	}
	
function print_javascript_function_show_step_popup($pageNum) {
	echo "
<script>
function stepPopup(Scene_id, Page) {
	
		var stepPopup_text = 'stepPopupUL' + Page;
		var stepPopup = document.getElementById(stepPopup_text);
		var xmlHttp = null;
		var html = '';

	try {
		// Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
		xmlHttp = new XMLHttpRequest();
	} catch(e) {
		try {
			// MS Internet Explorer (ab v6)
			xmlHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
		} catch(e) {
			try {
				// MS Internet Explorer (ab v5)
				xmlHttp = new ActiveXObject(\"Msxml2.XMLHTTP\");
			} catch(e) {
				xmlHttp = null;
				alert('Fehler');
			}
		}
	}

	if (xmlHttp) {
		xmlHttp.open('GET', 'get_step_scene?SceneID=' + Scene_id, true);
		xmlHttp.onreadystatechange = function () {
       			 if (xmlHttp.readyState == 4) {
					 	html = xmlHttp.responseText;
						stepPopup.innerHTML = html;
						$('#stepPopupUL$pageNum').listview('refresh');
						$('#stepPopup$pageNum').popup('open');
        		}
    	};		
		xmlHttp.send(null);		
	} else {
		
	}		
		
}	


</script>";
}

?>

